import os

from os import listdir
from os import path as op

def search(path):
    files = listdir(path)
    for file in files:
        ###路劲拼接
        filepath = path + "\\" + file
        if op.isdir(filepath):
            #当前file如果是路劲，递归调用
            search(filepath)
        else:
            #当前file如果是文件，添加到文件列表
            filelist.append(filepath)

def count(filelist):
    size = sum([op.getsize(file) for file in filelist])
    length = len(filelist)
    print("文件总数：", length)
    print("文件总大小：", size)

filelist = []
files_dir = r'E:\ftp'
search(files_dir)
count(filelist)
